@extends('app')

@section('content')
<script type="text/javascript">
function del(delid){
    var token = $('meta[name="_token"]').attr('content');
    if(confirm('是否删除用户？')){
        $.post("{{url('admin/del/')}}", { id: delid, _token: token },
        function(data){
            alert("消息: " + data);
            location.reload();
    });
    }
}

</script>
<div class="row  border-bottom white-bg dashboard-header">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>用户列表</h5>
            @if(isset($add))
            <a class="btn btn-outline btn-success pull-right" href="{{url('admin/'.$add->name)}}">{{$add->display_name}}</a>
            @endif
        </div>
        <div class="ibox-content">

            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>邮箱</th>
                        <th>用户</th>
                        <th>所属管理组</th>
                        <th>登录时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                @foreach($users as $user)
                    <tr>
                        <td>{{$user->id}}</td>
                        <td>{{$user->email}}
                        </td>
                        <td>{{$user->name}}</td>
                        <td>
                        @foreach($user->role as $role)
                            {{$role->display_name}}
                        @endforeach
                        </td>

                        <td>{{$user->updated_at}}</td>
                        <td>

                        @foreach($perms as $perm)
                        @if(Auth::user()->can($perm->name))
                            @if(!$user->hasRole('god'))
                            <a class="btn btn-outline btn-success"
                            @if($perm->name == 'del')
                            onclick="del({{$user->id}})"
                            @else
                            href="{{url('admin/'.$perm->name.'/'.$user->id)}}"
                            @endif
                            >{{$perm->display_name}}</a>
                            @elseif($perm->name == 'view')
                            <a class="btn btn-outline btn-success" href="{{url('admin/'.$perm->name.'/'.$user->id)}}">{{$perm->display_name}}</a>
                            @endif
                        @endif
                        @endforeach
                        </td>
                    </tr>
                @endforeach
                </tbody>

            </table>
            <nav>{!! $users->render() !!}</nav>
        </div>

        
    </div>
</div>

@stop